import { defineStore } from 'pinia'
import axios from '../utils/axios'

// class NoteModel {
//   constructor() {
//     this.id = ''
//     this.title = ''
//     this.content = ''
//   }
// }

export const noteStore = defineStore('note', {
  state: () => ({
    text: 'Hello Editor',
    noteList: [
      {
        title: 'Ant Design Title 1'
      }
    ],
    noteModel: {}

  }),
  actions: {
    async fetchMessage() {
      const response = await fetch('http://127.0.0.1:5173/message')
      const data = await response.json()
      this.message = data.message
    },

    async add() {
      const data = {
        title: '测试标题js',
        content: ''
      }
      axios.post('/gin/note/save', data).then((response) => {
        console.log(response.data)
      })
    },

    async getList() {
      const response = await axios.get('/gin/note/list')
      this.noteList = response.data.data
    },

    async read(id) {
      const response = await axios.get(`/gin/note/read?id=${id}`)
      this.noteModel = response.data.data
    }

  }

})
